/*
 * Copyright (C) 2009 Juan Alberto López Cavallotti
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; version 2
 * of the License.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

package parameters;

import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * Models the program persistent settings.
 * @author juan
 */
public class Parameters {
    private Set<Profile> profiles;
    private String userName;
    private int protocolVersion;

    private static Parameters instance = new Parameters();

    private Parameters() {

        profiles = new HashSet<Profile>();
        userName = "";


        //TODO remove the following hardcoding
        Profile harcoded = new Profile("proyectos", UUID.randomUUID().toString(), "/home/juan/NetBeansProjects");
        profiles.add(harcoded);
        userName = "testUser";
        protocolVersion = 1;
    }

    public static Parameters getInstance() {
        return instance;
    }

    public Set<Profile> getProfiles() {
        return profiles;
    }

    public void setProfiles(Set<Profile> profiles) {
        this.profiles = profiles;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }
    
    /**
     * The protocol version that the networking module will use.
     * @return
     */
    public int getProtocolVersion() {
        return protocolVersion;
    }

    public void setProtocolVersion(int protocolVersion) {
        this.protocolVersion = protocolVersion;
    }

    public static void load(ParameterLoader pl) {
        try {
            if (pl == null) {
                throw new Error("Null parameter loader");
            }
            instance = new Parameters();
            pl.load(instance);

            //TODO add throws clause when custom exception is added
            
        } catch (Exception ex) {
            Logger.getLogger(Parameters.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

}
